package org.alex.sample.web;

import java.util.List;

import org.alex.sample.VO.ExamScoreVO;
import org.alex.sample.model.ExamScore;
import org.alex.sample.model.Subject;
import org.alex.sample.page.PagerModel;
import org.alex.sample.service.ExamScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ExamScoreController {
	
	@Autowired
	private ExamScoreService examScoreService;
	
	//成绩列表
	@RequestMapping(value = "/scores")
	public String managerExamScore(Model model) throws Exception{
		PagerModel<ExamScore> pager = examScoreService.findAllExamScore();
		model.addAttribute("pager", pager);
		return "managerScore/examScoreList";
	}
	
	//查询科目名和id
	@ResponseBody
	@RequestMapping(value = "/findSubjectNameAndId")
	public List<Subject> findSubjectNameAndId() throws Exception{
		List<Subject> subjectList = examScoreService.findSubjectNameAndId();
		return subjectList;
	}
	
	//按条件搜索
	@ResponseBody
	@RequestMapping(value = "/searchExamScore")
	public List<ExamScoreVO> searchExamScore(Model model, @RequestParam(name = "subjectName", required = false) 
		Integer subId, @RequestParam(name = "userName", required = false) String userName, 
		@RequestParam(name = "name", required = false) String name, 
		@RequestParam(name = "examTime", required = false) String examTime) throws Exception{
		List<ExamScoreVO> examScoreVOList = examScoreService.searchExamScore(subId, userName, name, examTime);
		return examScoreVOList;
	}

}
